package com.jeesite.modules.sys.utils;

import com.jeesite.common.config.Global;
import com.jeesite.common.io.FileUtils;
import com.jeesite.common.lang.DateUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.File;

/**
 * Created by MacBook on 2019/4/30.
 */
public class PathUtils {

    //创建保存到本地的文件路径
    public static String getFilePath(String officeName,String baseType,String name) {
        String filePath =  Global.getUserfilesBaseDir(officeName + File.separator + baseType + File.separator + name + File.separator
                + DateUtils.getYear() + File.separator
                + DateUtils.getMonth() + File.separator
                + DateUtils.getDay() + File.separator);
        FileUtils.createDirectory(filePath);
        return filePath;
    }

    //创建保存到数据库的文件路径
    public static String getSavePath(HttpServletRequest request, String officeName, String baseType, String name) {
        String savePath = request.getContextPath() + officeName + File.separator + baseType + File.separator + name + File.separator
                + DateUtils.getYear() + File.separator
                + DateUtils.getMonth() + File.separator
                + DateUtils.getDay() + File.separator;
        return savePath;
    }

}
